<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="br.com.conexao.fateca.Conexao"%>
<!DOCTYPE html>

<%
    Connection con = null;
    Statement stat = null;
    ResultSet rs = null;

    if (request.getParameter("acao") != null) {
        con = Conexao.getConnection();
        PreparedStatement ps = con.prepareStatement("DELETE FROM aluno WHERE cd_matricula = '" + request.getParameter("cdMatricula") + "'");
        ps.execute();
        ps.close();
    }

%>
<html lang="pt-br">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <title>Fateca</title>
        <meta name="generator" content="Bootply" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <link href="css/styles.css" rel="stylesheet">
    </head>
    <body>

        <div id="wrap">


            <%@include file="includes/header.jsp" %>



            <div class="container">
                <div class="page-header">
                    <h1>Alunos</h1>
                </div>

                <%
                    con = Conexao.getConnection();
                    stat = con.createStatement();
                    rs = stat.executeQuery("SELECT * FROM aluno");

                    out.println("<table class='table'>");
                    out.println("<th>Matricula</th>");
                    out.println("<th>Nome do Aluno</th>");
                    out.println("<th>Curso</th>");
                    out.println("<th>Telefone</th>");
                    out.println("<th>Periodo</th>");
                    out.println("<th>Email</th>");
                    while (rs.next()) {
                        out.println("<tr>");
                        out.println("<td>" + rs.getString("cd_matricula") + "</td>");
                        out.println("<td>" + rs.getString("nm_aluno") + "</td>");
                        out.println("<td>" + rs.getString("nm_curso") + "</td>");
                        out.println("<td>" + rs.getString("cd_telefone") + "</td>");
                        out.println("<td>" + rs.getString("nm_periodo") + "</td>");
                        out.println("<td>" + rs.getString("nm_email") + "</td>");
                                        
                                        
                        out.println("<td>");
                        out.println("<a class='btn btn-info btn-xs' href='cadaluno.jsp?cdMatricula=" + rs.getString("cd_matricula") + "&acao=editar'><span></span> Editar</a>");
                        out.println("</td>");
                        out.println("<td>");
                        out.println("<a class='btn btn-danger btn-xs' href='lstaluno.jsp?cdMatricula=" + rs.getString("cd_matricula") + "&acao=remover'><span></span> Remover</a>");
                        out.println("</td>");
                        out.println("</tr>");

                    }
                    out.println("</table>");

                %>

            </div>
        </div>

        <!-- script references -->
        <%@include file="includes/footer.jsp" %>


    </body>
</html>